package com.review.cli;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.review.graph.CallGraphService;
import com.review.model.CallGraphBuildRequest;
import com.review.model.CallGraph;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "cg", description = "Build or query Java method call graph")
public class CallGraphCommand implements Runnable {

	@Option(names = "--path", defaultValue = ".", description = "Project root path")
	private String projectPath;

	@Option(names = "--precision", defaultValue = "CHA", description = "CHA|RTA (placeholder)")
	private String precision;

	@Override
	public void run() {
		try {
			CallGraphService service = new CallGraphService();
			CallGraphBuildRequest req = new CallGraphBuildRequest(projectPath, precision);
			CallGraph graph = service.build(req);
			ObjectMapper om = new ObjectMapper();
			System.out.println(om.writerWithDefaultPrettyPrinter().writeValueAsString(graph));
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}

